package com.joinval.modules.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.joinval.common.utils.PageUtils;
import com.joinval.common.utils.Result;
import com.joinval.modules.sys.entity.SysRule;
import com.joinval.modules.sys.service.SysRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.format.DecimalStyle;
import java.util.List;
import java.util.Map;


/**
 * 规则表
 *
 * @author chen
 * @email null
 * @date 2020-11-13 16:39:51
 */
@RestController
@RequestMapping("vol/sysRule")
@Api(description = "规则相关")
public class SysRuleController {

    @Autowired
    private SysRuleService sysRuleService;

    /**
     * 列表
     */
    @ApiOperation(value="列表")
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = sysRuleService.queryPage(params);
        return Result.ok().data(page);
    }

    @ApiOperation(value = "规则列表")
    @GetMapping("/rules")
    public Result rules() {
        List<SysRule> sysRules = sysRuleService.rules();
        return Result.ok().data(sysRules);
    }


    /**
     * 信息
     */
    @ApiOperation(value="信息")
    @GetMapping("/info/{sysRuleId}")
    public Result info(@PathVariable("sysRuleId") Long sysRuleId){
		SysRule sysRule = sysRuleService.getById(sysRuleId);
        return Result.ok().data(sysRule);
    }

    /**
     * 新增
     */
    @ApiOperation(value="新增")
    @PostMapping("/save")
    public Result save(@RequestBody SysRule sysRule){
        Boolean result = sysRuleService.save(sysRule);
        return result?Result.ok():Result.error("保存失败");
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public Result update(@RequestBody SysRule sysRule){
        Boolean result = sysRuleService.updateById(sysRule);
        return result?Result.ok():Result.error("更新失败");
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete/{sysRuleId}")
    public Result delete(@PathVariable("sysRuleId") Long sysRuleId){
        Boolean result = sysRuleService.removeById(sysRuleId);
        return result?Result.ok():Result.error("删除失败");
    }

}
